const app = getApp();

let common=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.serverUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let commonIot=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.serverUrlIot + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let nb=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.nbUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let equipment=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.equipmentUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let equipmentIot=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.equipmentUrlIot + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let equipment2=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: app.globalData.equipmentUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let authority=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.authorityUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let authority2=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: app.globalData.authorityUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let wechat=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.wechatUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//用于验证码登录
let wechat2=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      url: app.globalData.wechatUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let report=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url: app.globalData.reportUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let go=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let goProjectRules=function(url,data){
    return new Promise((resolve,reject)=>{
      wx.request({
        header: {
          'Content-Type': "application/json;charset=UTF-8",
          'Authorization': 'Bearer ' + app.globalData.loginToken,
        },
        url:app.globalData.goProjectRules + url,
        method: "POST",
        data: data,
        success(res) {
          resolve(res);
        },
        fail(){
          reject();
        }
      })
    });
  }

let goChart=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goChart + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let goDataOpr=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goDataOpr + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let goDataOprIot=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goDataOprIot + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let goPersonCenter=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goPersonCenter + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


let goDataReport=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goDataReport + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


let goNb=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goNb + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}
//用友接口
let yy=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.yy + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//电子工牌相关
let goCard=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goCardUrl + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//有效工作时间和活跃度详情
let pythonEffectiveDetail=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.pythonEffectiveDetail + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


//go项目-equipment
let goEquipment=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goEquipment + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//go项目-UI
let goUI=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.goUI + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

//健康
let health=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.healthLog + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


//同步pcsql数据库
let syncPgSql=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.syncPgSql + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}
//有效工作时间和活跃度详情
let sendInstruction=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.sendInstruction + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}

let sendMessageTTS=function(url,data){
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.sendMessageTTS + url,
      method: "POST",
      data: data,
      success(res) {
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


let task=function(url,data){
  console.log("url,data");
  console.log(app.globalData.task + url);
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.task + url,
      method: "POST",
      data: data,
      success(res) {
        console.log(res);
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}


let storage=function(url,data){
  console.log("url,data");
  console.log(app.globalData.storage + url);
  return new Promise((resolve,reject)=>{
    wx.request({
      header: {
        'Content-Type': "application/json;charset=UTF-8",
        'Authorization': 'Bearer ' + app.globalData.loginToken,
      },
      url:app.globalData.storage + url,
      method: "POST",
      data: data,
      success(res) {
        console.log(res);
        resolve(res);
      },
      fail(){
        reject();
      }
    })
  });
}




module.exports = {
  common:common,  
  nb:nb,
  equipment:equipment,
  equipment2:equipment2,
  authority:authority,
  wechat:wechat,
  wechat2:wechat2,
  authority2:authority2,
  report:report,
  go:go,
  goChart:goChart,
  goDataReport:goDataReport,
  goDataOpr:goDataOpr,
  goNb:goNb,
  goPersonCenter:goPersonCenter,
  yy:yy,
  goCard:goCard,
  goEquipment:goEquipment,
  goUI:goUI,
  commonIot: commonIot,
  goDataOprIot: goDataOprIot,
  equipmentIot: equipmentIot,
  syncPgSql: syncPgSql,
  health: health,
  pythonEffectiveDetail:pythonEffectiveDetail,
  sendInstruction:sendInstruction,
  goProjectRules:goProjectRules,
  sendMessageTTS:sendMessageTTS,
  task:task,
  storage:storage
}
